import java.util.StringTokenizer;

PFont font;
static String filename = "Cry3_associated_peptides_merge.tab";
static String contigCollectionName = "Cry3 associated peptides";

int windowWidth = 1300;
int windowHeight = 710;//760;
float xBorderSize;
float yBorderSize;

float contigSpaceHeight; //this is calculated by partitionVerticalSpace function
float gapsBetweenContigs; //this is calculated by partitionVerticalSpace function
float borderSize; //size of empty space around edge of window
float maxContigWidth; //maximum horizontal space consumed by contig 

ContigCollection contigs;
//MouseWheelEventDemo wheel;

//MenuBox menuBox;

//variables for interactivity
boolean controlKeyPressed;

void setup()
{
  initZoom();
  size( windowWidth, windowHeight ); 
  addMouseWheelListener(new java.awt.event.MouseWheelListener() { 
    public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) { 
      mouseWheel(evt.getWheelRotation());
  }}); 

  font = createFont("SansSerif", 20);
  textFont( font );
  
  xBorderSize = .05*(float)windowWidth; //make the border a fraction of the width and height
  yBorderSize = .05*(float)windowHeight;
  
  contigs = new ContigCollection( filename, contigCollectionName, xBorderSize, yBorderSize, windowWidth-xBorderSize, windowHeight-yBorderSize  );
  //wheel = new MouseWheelEventDemo();

  //initZoom(contigs.getNumberOfContigs);
  
}

void draw()
{
  background( 0 );
  zoomUpdate();
  contigs.draw();
}

//-----------------------------------------------SETUP METHODS------------------------------------------------

//--------------------------------------------END SETUP METHODS-----------------------------------------------

//------------------------------------------INTERACTIVITY METHODS----------------------------------------------

void keyPressed()
{
  if( key == 'a' )//CONTROL )
    controlKeyPressed = true;
  if( key == 's' )
    contigs.sortAndRearrange();
}

void keyReleased()
{
  if( key == 'a' )
    controlKeyPressed = false;
}

void mousePressed()
{
  if( controlKeyPressed )
    contigs.selectionMade(mouseX, mouseY);
}

void mouseDragged()
{
  println("mouseX = " + mouseX + " mouseY = " + mouseY );
  moveInSpace();
}

void mouseReleased()
{
  stopMoveInSpace();
}

void mouseWheel(int delta) {
  println(delta); 
  if( delta > 0 )
    zoomOut();
  else
    zoomIn();
}


//---------------------------------------END INTERACTIVITY METHODS----------------------------------------------- 
